package cn.congzhou.crm.service.impl;

import cn.congzhou.crm.common.qo.QueryObject;
import cn.congzhou.crm.common.vo.PageTableData;
import cn.congzhou.crm.domain.School;
import cn.congzhou.crm.mapper.SchoolMapper;
import cn.congzhou.crm.service.ISchoolService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SchoolServiceImpl implements ISchoolService{

    @Autowired
    private SchoolMapper schoolMapper;

    @Override
    public PageTableData<School> queryShool(QueryObject qo) {
        Page page = PageHelper.startPage(qo.getPage(),qo.getLimit());
        List<School> schools = schoolMapper.selectAll();
        PageTableData pageTableData = new PageTableData<>(page.getTotal(),schools);
        return pageTableData;
    }

    @Override
    public void saveOrUpdate(School school) {
        if (school.getId() == null){
            schoolMapper.insert(school);
        }else {
            schoolMapper.updateByPrimaryKey(school);
        }
    }

    @Override
    public void deleteById(Long id) {
        schoolMapper.deleteByPrimaryKey(id);
    }
}
